#ifndef PSD_LISTENER_H
#define PSD_LISTENER_H

#include "psd_conn.h"

enum listener_status { LISTENER_STOPPED, LISTENER_RUNNING };

typedef struct psd_listener_t {
	char *id;
	enum listener_status status;

	const char *protocol;
	psdSettings *settings;
	int one_shot;
	int (*callback) (struct psd_listener_t *listener, struct psd_connection_t *conn, void *arg);
	void *arg;

	void *proto_private;

	int (*start) (struct psd_listener_t *listener);
	int (*stop) (struct psd_listener_t *listener);
	void (*free) (struct psd_listener_t *listener);

	int references;

	pthread_mutex_t lock;
} psdListener;

typedef int (*listener_cb) (psdListener *listener, struct psd_connection_t *conn, void *arg);

psdListener *psd_listener_alloc();
psdListener *psd_listener_alloc_set(const char *listener_id, const char *protocol, psdSettings *settings, int one_shot, listener_cb callback, void *arg);
void psd_listener_free(psdListener *listener);

int psd_listener_start(psdListener *listener);
int __psd_listener_start(psdListener *listener);
int psd_listener_stop(psdListener *listener);
int __psd_listener_stop(psdListener *listener);

psdListener *psd_listener_get_ref(psdListener *listener);
void psd_listener_put_ref(psdListener *listener);

#endif
